package com.cheng.dreams.sample.presenter.pay;

import android.content.Context;

import com.cheng.dreams.sample.contract.pay.PayContract;
import com.cheng.dreams.sample.entity.request.PayRequest;
import com.cheng.dreams.sample.entity.response.BaseResponse;
import com.cheng.dreams.sample.entity.response.PayEntity;
import com.cheng.dreams.sample.net.HandleErrorObserver;
import com.cheng.dreams.sample.presenter.BasePresenter;


/**
 * Created by Snow on 2017/3/4.
 * Description:
 */

public class PayPresenter extends BasePresenter implements PayContract.Presenter {
    private PayContract.View mView;

    public PayPresenter(PayContract.View view, Context mContext) {
        super(mContext);
        mView = view;
    }
    @Override
    public void pay(PayRequest request) {
        mView.showLoading();
        mService.getPay(request.getJson())
                .compose(mObservableTransformer)
                .subscribe(new HandleErrorObserver<BaseResponse<PayEntity>>(mView, request) {
                    @Override
                    public void onSuccess(BaseResponse<PayEntity> response) {
                        mView.onPaySuccess(response.getData());
                    }
                });
    }
}
